package com.example.lib_core.mvp.view;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.lib_core.init.Core;
import com.example.lib_core.mvp.presenter.IPresenter;
import com.tbruyelle.rxpermissions2.RxPermissions;

public abstract class BaseFragment<P extends IPresenter> extends Fragment implements IView,IFragment{
   protected  P mPresenter;
   private View mView;
//    private RxPermissions rxPermissions;
//    //提供权限申请
//    public RxPermissions getRxPermissions() {
//        if(rxPermissions==null){
//            rxPermissions=new RxPermissions(getActivity());
//        }
//        return rxPermissions;
//    }
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = LayoutInflater.from(getContext()).inflate(bondLayout(), container,false);
        return mView;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
        inject();
        initData();
    }

    @Override
    public <T extends View> T findViewById(int id) {
        return mView.findViewById(id);
    }

    @Override
    public void Toast(String string) {
        Toast.makeText(Core.getInstance().getApplication(), ""+string, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if(mPresenter!=null){
            mPresenter.onDestroy();
            mPresenter=null;
        }
    }
}
